<%@page import="com.crossriver.crgis.database.service.Bank_Payment_SlipLocalServiceUtil"%>
<%@page import="com.crossriver.crgis.database.model.Bank_Payment_Slip"%>
<%@page import="com.crossriver.crgis.database.model.Transactions"%>
<%@page import="com.crossriver.crgis.database.service.TransactionsLocalServiceUtil"%>
<%@page import="com.liferay.portal.service.OrganizationLocalServiceUtil"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.liferay.portal.kernel.util.ListUtil"%>
<%@page import="javax.portlet.PortletURL"%>
<%@page import="com.liferay.portal.kernel.util.WebKeys"%>
<%@page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@page import="com.liferay.portal.model.User"%>
<%@page import="java.util.List"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ include file="/init.jsp"%>

<portlet:defineObjects />

<div id="main">
	<h1>Transaction History</h1>
	<div class="content">
	
		<p>
			Here, you can view all transaction history concerning your account.
		</p>
		<p>
      If you notice any transaction made in your favour without your knowledge or 
      acknowledgement, kindly contact us immediately, so that we can respond on time.
	  </p>
	  <hr>

			<%
			
			ThemeDisplay themeDiply = (ThemeDisplay) request
			.getAttribute(WebKeys.THEME_DISPLAY);
			
			String userId = "" + themeDiply.getUserId(); 
		
			%>
		<aui:layout>
	 		<aui:column columnWidth="100">
      
      <% 
				PortletURL iteratorURLSend = renderResponse.createRenderURL();
				iteratorURLSend.setParameter("jspPage", "/html/transactions/view.jsp");
			%>
						
			<liferay-ui:search-container id="users" 
				emptyResultsMessage="no-transaction-found" delta="20" iteratorURL="<%= iteratorURLSend %>" >
				<liferay-ui:search-container-results>
					<%
							List<Transactions> tempTransactions = TransactionsLocalServiceUtil.getTransactionsbyUser(userId);

							
							results = ListUtil.subList(tempTransactions,
								searchContainer.getStart(),
								searchContainer.getEnd());
		
							total = tempTransactions.size();
		
							pageContext.setAttribute("results", results);
							pageContext.setAttribute("total", total);
					%>
				</liferay-ui:search-container-results>

				<liferay-ui:search-container-row 
					className="com.crossriver.crgis.database.model.Transactions" keyProperty="transactionNo" modelVar="transaction">
	
					<%
						SimpleDateFormat sdf = new SimpleDateFormat( "dd MMM yyyy hh:mm:ss");
						String paymentDate =  sdf.format(transaction.getPaymentDate());
					%>
	
					<liferay-ui:search-container-column-text name="Payment Date" value="<%= paymentDate%>" />
					<liferay-ui:search-container-column-text name="Transaction No" property="transactionNo" />
					<liferay-ui:search-container-column-text name="Payment Type" property="paymentType" />
					<liferay-ui:search-container-column-text name="Amount Paid" property="amount" />
					<liferay-ui:search-container-column-text name="Reference No" property="retRef" />
					<liferay-ui:search-container-column-text name="Response Description" property="responseDescription" />
					<liferay-ui:search-container-column-text name="Status" property="status" />
					<liferay-ui:search-container-column-jsp name="Action" path="/html/transactions/display_actions.jsp" align="right" />
					
					<%
						long groupId = themeDiply.getLayout().getGroupId();
						String name = User.class.getName();
						//String usrId = String.valueOf(user.);
					%>
	
				</liferay-ui:search-container-row>
				<liferay-ui:search-iterator searchContainer="<%= searchContainer %>" />
			</liferay-ui:search-container>
      
     </aui:column>
	 </aui:layout> 


	  <hr>

		Direct Payment made to bank with the uploaded Payment Slips. 
		Payment items that have been identified are automatically identified as valid transactions.
			<%
			
			%>
		<aui:layout>
	 		<aui:column columnWidth="100">
      
      <% 
				PortletURL iteratorURLSend = renderResponse.createRenderURL();
				iteratorURLSend.setParameter("jspPage", "/html/transactions/view.jsp");
			%>
						
			<liferay-ui:search-container id="users" 
				emptyResultsMessage="no-transaction-found" delta="20" iteratorURL="<%= iteratorURLSend %>" >
				<liferay-ui:search-container-results>
					<%

						List<Bank_Payment_Slip> tempBankSlips = Bank_Payment_SlipLocalServiceUtil.getDepositSlipsbyUser(userId);
						
							results = ListUtil.subList(tempBankSlips,
								searchContainer.getStart(),
								searchContainer.getEnd());
		
							total = tempBankSlips.size();
		
							pageContext.setAttribute("results", results);
							pageContext.setAttribute("total", total);
					%>
				</liferay-ui:search-container-results>

				<liferay-ui:search-container-row 
					className="com.crossriver.crgis.database.model.Bank_Payment_Slip" keyProperty="depSlipNo" modelVar="depSlip">
	
					<%
						SimpleDateFormat sdf = new SimpleDateFormat( "dd MMM yyyy hh:mm:ss");
						String registedDate =  sdf.format(depSlip.getRegistedDate());
					%>
	
					<liferay-ui:search-container-column-text name="Registered Date" value="<%= registedDate%>" />
					<liferay-ui:search-container-column-text name="Payment Slip No" property="depSlipNo" />
					<liferay-ui:search-container-column-text name="Depositor's Name" property="depositorName" />
					<liferay-ui:search-container-column-text name="Approved Amount" property="approvedAmount" />
					<liferay-ui:search-container-column-text name="Amount Paid" property="paidAmount" />
					<liferay-ui:search-container-column-text name="Bank Name" property="bankName" />
					<liferay-ui:search-container-column-text name="Status" property="status" />
					<liferay-ui:search-container-column-jsp name="View Uploaded File" path="/html/transactions/view_slip.jsp" align="right" />
					
					<%
						long groupId = themeDiply.getLayout().getGroupId();
						String name = User.class.getName();
						//String usrId = String.valueOf(user.);
					%>
	
				</liferay-ui:search-container-row>
				<liferay-ui:search-iterator searchContainer="<%= searchContainer %>" />
			</liferay-ui:search-container>
      
     </aui:column>
	 </aui:layout>
	</div>
</div>